import React from 'react';
import zhCN from '@/locales/zh-CN';
import enUS from '@/locales/en-US';

// todo
const langConfig = {
  curLang: 'zh-CN',
};

export const formatMessage = ({id}) => zhCN[id];

export const FormattedMessage = (props) => {
  let text = zhCN[props.id];
  const values = props.values;

  values && Object.keys(values).forEach(key => {
    const regex = new RegExp(`(\\{${key}\\})`, 'gi');
    text = text.replace(regex, values[key]);
  });
  return (<span>{text}</span>);
};

export const setLocale = (lang) => {
  langConfig.curLang = lang
};
export const getLocale = () => {
  return langConfig.curLang
};
